package com.trillion.toyou;

import java.util.ArrayList;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.LinearLayout;

public class NfcOnOffChange {
	LinearLayout topTitle = null;
	int on = 0;
	int off = 0;
	boolean check = true;
	
	
	public NfcOnOffChange(LinearLayout topTitle, int on, int off) {
		this.topTitle = topTitle;
		this.on = on;
		this.off= off;
		
		new TitleBarChange().execute(new ArrayList());
	}
	
	
	public class TitleBarChange extends AsyncTask<ArrayList, String, LinearLayout>{
		
		@Override
		protected void onPreExecute() {
			if(MainActivity.nfcAdapter.isEnabled()){
				topTitle.setBackgroundResource(on);
			}else{
				topTitle.setBackgroundResource(off);
			}
			
			super.onPreExecute();
		}
		
		
		
		@Override
		protected LinearLayout doInBackground(ArrayList... params) {
			long endTimer = System.currentTimeMillis() + 1500;
			
			long startTimer = 0;
			
			while (startTimer <= endTimer){
				startTimer = System.currentTimeMillis();
				if(MainActivity.nfcAdapter.isEnabled()){
					check = true;
				}else{
					check = false;
				}
			}
			
			
			return null;
		}
		
		@Override
		protected void onPostExecute(LinearLayout result) {
			if(check){
				topTitle.setBackgroundResource(on);
			}else{
				topTitle.setBackgroundResource(off);
			}
			
			super.onPostExecute(result);
		}
		
	}
}
